package com.Base;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by XingYang on 2019/3/13.
 * id派发中心
 */
public class IdCenter {
    public  static int Building = 1;
    public static int Land = 0;
    public static int isRemoved = 1;
    public static int notRemoved = 0;
    private Date date = new Date();
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    /**
     * 生成项目id
     * @param type 是否拆迁房  0 不是  1 是
     * */
    public String getProjectId(int type){
        StringBuilder sb = new StringBuilder();
        switch (type){
            case 0:
                sb.append("NO");//正常项目
                break;
            case 1:
                sb.append("CQ");//拆迁项目
                break;
            default:
                sb.append("UN");//其他项目 unknow
                break;
        }
        sb.append(sdf.format(date));
        sb.append(getRandom(4));

        return sb.toString();
    }

    /***
     *生成项目下对象id
     * @param projectid 项目id
     * @param objType 对象类型  0 土地  1 房产
     * @return id 对象id
     *
     */

    public String getObjId(String projectid,int objType){
        StringBuilder sb = new StringBuilder(projectid);
        switch (objType){
            case 0:
                sb.append("L");//land
                break;
            case 1:
                sb.append("B");//buding
                break;
            default:
                sb.append("U");//unknow
                break;
        }
        sb.append(getRandom(4));
        return sb.toString();
    }
/**
 * 返回1-6位随机数
 * @param length 随机数串长度
 * */
    public String getRandom(int length){
        if(length>6||length<1)
            length = 6;
        String result = "";
        Random rm= new Random();
        double pross = (1 + rm.nextDouble()) * Math.pow(10, length);
        result = String.valueOf(pross);
        return result.substring(0,length);
    }


}
